package com.tanhua.server.controller;

import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;
    /**
     * 首页-今日佳人
     * */

    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){
        //调用方法查询
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);

    }

    /**
     * 首页推荐
     *
     * */

    @GetMapping("/recommendation")
    public ResponseEntity recommendation(@RequestParam(defaultValue = "1")Integer page,
                                         @RequestParam(defaultValue = "10")Integer pagesize){
        //调用方法查询
        PageResult vo = tanhuaService.recommendation(page,pagesize);
        return ResponseEntity.ok(vo);
    }

    /**
     *佳人信息
     * */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId){
        TodayBest vo =   tanhuaService.personalInfo(userId);
        return ResponseEntity.ok(vo);
    }
    /**
     * 查看陌生人问题
     * */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){

       String question = tanhuaService.strangerQuestions(userId);
       return ResponseEntity.ok(question);
    }
    /**
     * 回复陌生人问题
     * */
    @PostMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestBody Map map){
        //获取参数
        String s = map.get("userId").toString();
        Long userId = Long.valueOf(s);
        String reply = map.get("reply").toString();
        //调用方法回复
        tanhuaService.reply(userId,reply);
        return ResponseEntity.ok(null);

    }
    /**
     * 搜附近
     * */
    @GetMapping("/search")
    public ResponseEntity search(String gender,String distance){
        List<NearUserVo> vos  = tanhuaService.search(gender,distance);
        return ResponseEntity.ok(vos);
    }
}
